#ifndef __XOBJECT_H__
#define __XOBJECT_H__

#include "math/math_config.h"
#include "util/utils.h"
#include <map>

NS_MATH_BEGIN

class XObjectData;
class XObject;

class XObjectData : public ::xphysics::util::ObjectData
{
public:
	typedef ::xphysics::util::ObjectData base_type;
	friend class XObject;

	virtual xstring name() const;

	virtual XObjectData* Clone() const;

protected:
	xstring m_sName;

};

class XObject : public ::xphysics::util::ObjectT<XObjectData>
{
public:
	typedef ::xphysics::util::ObjectT<XObjectData> base_type;
public:
	xstring name()const;
	bool isnil()const;
	
	// Transcript the ptr to a children-class pointer
	template<typename T>
	T* cast_ptr(){return dynamic_cast<T*>(ptr.get());}
	template<typename T>
	T& cast_ref(){return *(dynamic_cast<T*>(ptr.get()));}
	

	void set_data(XObjectData* ptr_);

	XObject Clone() const;

	XObject();
	XObject(XObject& obj);
	XObject(XObjectData* data_ptr);

protected:
	static std::map<xstring, XObject> obj_map;
	static void init();
	static XObject Create(const xstring& obj_typename);
};


NS_MATH_END

#endif
